<script type="text/javascript" src="/src/main/js/loader.js?classpath=/src/main/js|."></script>
<script>

    //////////////////////////////////////////////////////////////////////////////////////
    // Inheritance, v1 (functional approach)
    //////////////////////////////////////////////////////////////////////////////////////

    function MyParentClass_constructor() {
        this.d = 0;
    }

    function MyParentClass_test() {
        this.d++;
    }

    function MyChildClass_constructor() {
        MyParentClass_constructor.apply(this, arguments); // call super
    }

    function MyChildClass_test() {
        MyParentClass_test.apply(this, arguments); // call super
    }

    // Inheritance, v2 (classical)

    function MyParentClass() {
        this.MyParentClass();
    }

    MyParentClass.prototype.MyParentClass = function () {
        this.d = 0;
    };

    MyParentClass.prototype.test = function () {
        this.d++;
    };

    function MyChildClass() {
        this.MyChildClass();
    }

    MyChildClass.prototype = new MyParentClass();
    MyChildClass.prototype.MyChildClass = function () {
        this.MyParentClass();
    };
    MyChildClass.prototype._super_test = MyChildClass.prototype.test;
    MyChildClass.prototype.test = function () {
        this._super_test();
    };

    // Inheritance, v3 (jspecial)

    load('test.MyChildClass');
    load('test.MyParentClass');


    /////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////

    var o1 = new MyChildClass_constructor();
    var o2 = new MyChildClass();
    var o3 = new test.MyChildClass();

    console.info(o3 instanceof test.MyParentClass);
    console.info(o3 instanceof test.MyChildClass);

    console.info('Inheritance, v1 (functional approach)');
    (function (o) {
        var n = 1000000;
        var t = new Date();
        for (var i = 0; i < n; i++) {
            MyChildClass_test.apply(o);
        }
        console.log(new Date() - t);
        checkNum(o, n);
    })(o1);

    console.info('Inheritance, v2 (classical)');
    (function (o) {
        var n = 1000000;
        var t = new Date();
        for (var j = 0; j < n; j++) {
            o.test();
        }
        console.log(new Date() - t);
        checkNum(o, n);
    })(o2);

    console.info('Inheritance, v3 (jspecial)');
    (function (o) {
        var n = 1000000;
        var t = new Date();
        for (var i = 0; i < n; i++) {
            o.test();
        }
        console.log(new Date() - t);
        checkNum(o, n);
    })(o3);

    function checkNum(o, n) {
        var num = o.d;
        console.assert(num == n, 'Invalid number: expected ' + n + ' but actually ' + num);
    }

</script>
